package service

import (
	"fmt"
	"goapp-web-server/app/models"
	"goapp-web-server/app/utils/orm"
)

type CmsMaterialService interface {
	GetAll() ([]models.CmsMaterial, error)
	GetByID(id int64) models.CmsMaterial
}

func NewMaterialService() CmsMaterialService {
	return new(materialService)
}

type materialService struct {
}

// material list
func (s *materialService) GetAll() ([]models.CmsMaterial, error) {
	engine := orm.Engine
	list := make([]models.CmsMaterial, 0)
	err := engine.Table("cms_material").
		Select(`cms_material.*`).
		Where("cms_material.deleted_at is NULL").
		Limit(10, 0).
		Find(&list)
	if err != nil {
		fmt.Println("error:", err)
		return nil, err
	}
	return list, nil
}

// get material by id
func (s *materialService) GetByID(id int64) models.CmsMaterial {
	material := models.CmsMaterial{}
	fmt.Println(material.Name)
	return material
}
